package org.lmind.srd35.combat

import org.lmind.srd35._
import org.lmind.srd35.core._

class CombatActions {
  
  var _rule:Rule = null
  
  var _env:CombatEnvironment = null
  
  def attack(attacker:CombatUnit, target:CombatUnit) = {
    
    val result = _rule.attackRoll(attacker, attacker.weapon, target)
    
    // TODO 以后需要计算各伤害的抗性
    for (val d <- result.damage) {
      target.hp -= d._2
    }
  }
  
  def move(unit:CombatUnit, position:(Int, Int)) = {
    
    if (unit.distanceOf(position) > unit.race.baseLandSpeed)
        throw new SrdException()
    
    val speed = unit.race.baseLandSpeed
    val moveRange = _env.moveRange(position, speed)
    
    // 无法到达此区域
    if (!moveRange.contains(position)) {
      throw new SrdException()
    }
    
    _env.changePosition(unit, position)
  }
}